<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\admin\model\Goods;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;
Class good extends BaseController
{
    public function good_list()
    {

        $keywords=Request::get('keywords','','trim,htmlspecialchars,strip_tags');
        $recommended=Request::get('recommended','','trim,htmlspecialchars,strip_tags');
        $if_show=Request::get('if_show','','trim,htmlspecialchars,strip_tags');
//        echo $if_show;
//        exit;
        $cid=Request::get('cid','','trim,htmlspecialchars,strip_tags');
        $add_time1=Request::get('add_time1','','trim,htmlspecialchars,strip_tags');
        $add_time2=Request::get('add_time2','','trim,htmlspecialchars,strip_tags');
        $tname=Request::get('tname');
        $data=[
            'keywords'      =>$keywords,
            'recommended'   =>$recommended,
            'if_show'       =>$if_show,
            'cate_id'       =>$cid,
            'add_time1'     =>$add_time1,
            'add_time2'     =>$add_time2,
        ];

        if ($tname=='上架时间'){
            $tname='上架升序';
            $order="add_time asc";
        }elseif ( $tname=='上架升序')
        {
            $tname='上架降序';
            $order="add_time desc";
        }else{
            $tname='上架时间';
            $order="add_time";
        }
        $page=\think\facade\Config::has('view.list_rows')?\think\facade\Config::get('view.list_rows'):15;
        $alist =\app\admin\model\Goods::getGoods($data,$page,$order,input('get.',''));

        $ulist = \app\admin\model\Goods::getGcategory();
        View::assign('keywords',$keywords);
        View::assign('recommended',$recommended);
        View::assign('if_show',$if_show);
        View::assign('timer',$tname);
        View::assign('cid',$cid);
        View::assign('add_time1',$add_time1);
        View::assign('add_time2',$add_time2);
        View::assign($data);
        View::assign('ulist',$ulist);
        View::assign('alist',$alist);
        return  View::fetch();

//
//
//
//
//
//
//        if ($add_time1!='' and $add_time2!=''){
//            $a ->whereBetweenTime("add_time",$add_time1,$add_time2);
//        }
//        $alist = $a->paginate([
//            'list_tows'=>10,
//            'query' =>input('get.'),
//            'var_page'=>'p',
//        ]);
//        if ($keywords!=""){
//            foreach ($a as $k=>$v){
//                $a[$k]['goods_name']=
//                    str_replace($keywords,"<span style='color:red;font-weight:bold'>".$keywords."</span>",
//                        $a[$k]['goods_name']);
//            }
//        }
        //分类类表查询
//        $sql = Db::table('ecm_gcategory')
//            ->alias('c')
//            ->field('cate_id')
//            ->whereColumn('c.parent_id','g.cate_id')
//            ->limit(1)
//            ->buildSql();
//        $rt = Db::table('ecm_gcategory')
//            ->alias('g')
//            ->field('cate_id,cate_name,parent_id')
//            ->field($sql.'as has_next')
//            ->select();
//        $rt = Db::table('ecm_goods')
//            ->field(true)
//            ->whereIn('cate_id',function($query){
//            $query->table('ecm_gcategory')
//                ->field('cate_id')
//                ->where('if_show',1);
//        })->select();
//        echo "<pre>";
//        print_r($rt);
//        echo "</pre>";


    }
}